/**
 *  floppyread_bios()
 *  cteni z diskety na nejnizsi urovni
 */
void floppyread_bios(char cylinder, char head, char sector, char sectors, void far *offset) {
  int segment = (int)((long)offset >> 16);
  int addr    = (int)offset;

  asm cli;
  asm mov es, segment;
  asm mov bx, addr;
  asm mov ah, 2;
  asm mov al, sectors;
  asm mov ch, cylinder;
  asm mov dh, head;
  asm mov cl, sector;
  asm xor dl, dl;
  asm sti;
  asm int 0x13;

  return;
}

/**
 *  floppyread()
 *  do <buffer> nacte z diskety <secotrs> sektoru pocinaje
 *  sektorem <start>
 */
void floppyread(int start, int sectors, void far *buffer) {
  unsigned int c=0,
               h=0,
               s=start;

  s = start-1;
  c = ((s)/36);
  h = (((s)%36)/18);
  s = ((((s)%36)%18)+1);

  floppyread_bios((char)c,(char)h,(char)s, sectors, buffer);
  return;
}

/**
 *  floppywrite_bios()
 *  zapis na disketu na nejnizsi urovni
 */
void floppywrite_bios(char cylinder, char head, char sector, char sectors, void far *offset) {
  int segment = (int)((long)offset >> 16);
  int addr    = (int)offset;

  asm cli;
  asm mov es, segment;
  asm mov bx, addr;

  asm mov ah, 3;
  asm mov al, sectors;
  asm mov ch, cylinder;
  asm mov dh, head;
  asm mov cl, sector;
  asm xor dl, dl;
  asm sti;
  asm int 0x13;

  return;
}

/**
 *  floppywrite()
 *  z <buffer> zapise na disketu <secotrs> sektoru pocinaje
 *  sektorem <start>
 */
void floppywrite(int start, int sectors, void far *buffer) {
  unsigned int c=0,
               h=0,
               s=start;

  s = start-1;
  c = ((s)/36);
  h = (((s)%36)/18);
  s = ((((s)%36)%18)+1);

  floppywrite_bios((char)c,(char)h,(char)s, sectors, buffer);
  return;
}
